package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.common.R;
import com.example.entity.AdminSystem;
import com.example.service.AdminService;
import com.example.service.AdminSystemService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("adminSystems")
public class AdminSystemController {

    @Autowired
    private AdminSystemService adminSystemService;

    /**
     * 系统管理员登录
     * @return
     */
    @PostMapping("/loginAdminSystem")
    public R login(@RequestBody AdminSystem adminSystem){
        LambdaQueryWrapper<AdminSystem> lqw =new LambdaQueryWrapper<>();

        lqw.eq(Strings.isNotEmpty(adminSystem.getJobNumber()),AdminSystem::getJobNumber,adminSystem.getJobNumber());
        lqw.eq(Strings.isNotEmpty(adminSystem.getPassword()),AdminSystem::getPassword,adminSystem.getPassword());

        AdminSystem one = adminSystemService.getOne(lqw);
        if (one ==null){
            return R.error("登录失败！");
        }else {
            return R.success("登录成功！",one);
        }
    }
    /**
     * 根据id查询系统管理员信息
     * @return
     */
    @GetMapping("/getMyself/{id}")
    public R getMyself(@PathVariable int id){

        AdminSystem one = adminSystemService.getById(id);
        return R.success("根据id查询系统管理员信息(修改回显)",one);
    }
    /**
     * 根据id修改系统管理员信息
     * @return
     */
    @PutMapping("/updateAdminSystem")
    public R updateAdminSystem(@RequestBody AdminSystem adminSystem){
        LambdaQueryWrapper<AdminSystem> lqw =new LambdaQueryWrapper<>();

        boolean b = adminSystemService.updateById(adminSystem);
        if (b){
            return R.success("根据id修改系统管理员信息成功",adminSystem);
        }else {
            return R.error("根据id修改系统管理员信息失败");
        }
    }


}

